/******************************************************************************
 *                                                                            *
 *                    OS API                                                  *
 *                                                                            *
  ******************************************************************************/

/*-------------------------------------------------------------------
 * to avoid multiple definition if the file is included several times
 *-------------------------------------------------------------------*/
#ifndef OS_H
#define OS_H

#include "OS_Cfg.h"

/*----------------------------------------------------------------------------*
 *                     --- Local constants & typedefs ---                     *
 *----------------------------------------------------------------------------*/


typedef enum
{
	OS_NoError,
	OS_IdOutOfRange,
	OS_TimerInUse,
    OS_PipeEmpty,
    OS_PipeNotEmpty,
    OS_PipeFull,
    OS_BufferTooSmall,
	OS_InvalidParameter
} OS_Error;



typedef void (*pTaskHandler)(void);
typedef struct
{
    OS_TimeType     Expiration;
	OS_TimeType 	Reload;
    OS_IndexType    Schedule;
    pTaskHandler    pTask;
} OS_TaskType;

typedef struct
{
	volatile OS_TimeType	Tick;					// OS tick, incremented by hardware interrupt

    volatile OS_IndexType   TasksToSchedule;        // Number of tasks ready for scheduling
} OS_ControlType;


/*----------------------------------------------------------------------------*
 *                         --- Global Variables ---                           *
 *----------------------------------------------------------------------------*/



/*----------------------------------------------------------------------------*
 *                          --- Public functions ---                          *
 *----------------------------------------------------------------------------*/

#pragma CODE_SEG NON_BANKED

#ifdef __cplusplus
extern "C"
{
#endif


void OS_Init(void);
void OS_InitTimer(void);
void OS_InitInterrupt(void);

void OS_Run(void);

void OS_Wait(OS_TimeType time);

void OS_StartupHook(void);

/*
All these functions have been macro defined for target optimisation
PUBLIC void OS_EnableInterrupt(OS_InterruptID InterrruptID);
PUBLIC void OS_DisableInterrupt(OS_InterruptID InterrruptID);
PUBLIC void OS_EnableAllInterrupts(void);
PUBLIC void OS_DisableAllInterrupts(void );
*/

#ifdef __cplusplus
}
#endif

#pragma CODE_SEG DEFAULT

// Timers need to know about OS_Control struct because of system tick
extern OS_ControlType OS_Control;


// Tasks related defines
#define BEGIN_TASKS OS_TaskType OS_TaskArray[OS_MaxTask] = {
#define DECLARE_TASK(name, time)	{time,time,0,name},
#define END_TASKS };
extern OS_TaskType OS_TaskArray[OS_MaxTask];

#endif /* OS_h*/
/******************************************************************************
 *                               End of file                                  *
 ******************************************************************************/

